<template>
  <div class="qy pad_20">
    <el-form :model="formData" label-width="120px">
      <el-form-item label="购卡返利标题" prop="rebateTitle" :required="true">
        <el-input type="text" v-model="formData.rebateTitle" placeholder="请输入购卡返利标题"></el-input>
      </el-form-item>
      <el-form-item label="购卡返利副标题" prop="rebateSubtitle" :required="true">
        <el-input type="text" v-model="formData.rebateSubtitle" placeholder="请输入购卡返利副标题"></el-input>
      </el-form-item>
      <el-form-item label="购卡免配送费">
        <el-checkbox-group v-model="deliveryOpen" @change="change">
          <el-checkbox label="1">启用</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="购卡送优惠券" label-width="100px">
        <el-select v-model="formData.couponArr" multiple default-first-option placeholder="请选择优惠券">
          <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
<!--        <div>-->
<!--          <div v-for="(item,index) in continuity" :key="index" class="mar_b10">-->
<!--            <el-select  v-model="item.couponArr" placeholder="无" class="givecoupon">-->
<!--              <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id"></el-option>-->
<!--            </el-select>-->
<!--            <el-input-number v-model="item.num" controls-position="right" :min="1" :max="1000000" class="mar_l20"></el-input-number>-->
<!--            <span class="mar_l10">张</span>-->
<!--            <el-button size="mini" type="text" @click="delSpecMethod(index)" class="mar_l20">删除</el-button>-->
<!--          </div>-->
<!--          <div class="addgoods textbutton" v-show="this.continuity.length<10">-->
<!--            <i class="el-icon-plus"></i>-->
<!--            <el-button  type="text" class="" @click="addSpecMethod">添加优惠券</el-button>-->
<!--            <span class="yb_margin lh16 mar_l10">最多可添加10条</span>-->
<!--          </div>-->
<!--        </div>-->
      </el-form-item>
    </el-form>
    <div class="mar_t20 t_c">
      <el-button type="primary" @click="submitForm">保存</el-button>
    </div>
  </div>
</template>

<script>
import { vip_couponList } from '@/api/plug';
import { getConfig, postConfig } from '@/api/setup.js';
export default {
  data() {
    return {
      formData: {
        ident: 'payVipRebate',
        rebateTitle: '',
        rebateSubtitle: '',
        deliveryOpen: 2,
        couponArr: []
      },
      // continuity:[
      //   {
      //     couponId:[],
      //     num:'',
      //   }
      // ],
      deliveryOpen: [],
      options: []
    };
  },
  created() {
    vip_couponList().then((res) => {
      if (res.code == 1) {
        this.options = res.data;
        this.getConfigPay();
      }
    });
  },
  methods: {
    // addSpecMethod() {
    //   let specObj = {
    //     couponId:[],
    //     num:'',
    //   }
    //   this.$set(this.continuity, this.continuity.length, specObj)
    // },
    // delSpecMethod(index) {
    //   this.$delete(this.continuity, index)
    // },
    getConfigPay() {
      getConfig({
        ident: 'payVipRebate'
      }).then((res) => {
        Object.assign(this.formData, res.data);
        if (res.data.deliveryOpen == 1) {
          this.deliveryOpen = ['1'];
        } else {
          this.deliveryOpen = [];
        }
      });
    },
    change(msg) {
      if (msg.length) {
        this.formData.deliveryOpen = 1;
      } else {
        this.formData.deliveryOpen = 2;
      }
    },
    submitForm() {
      postConfig(this.formData).then((res) => {
        if (res.code == 1) {
          this.$baseMessage('保存成功！', 'success');
        }
      });
    }
  }
};
</script>
